//
//  CommentDetailTool.m
//  ForestPack
//
//  Created by jimmy on 2018/8/7.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "CommentDetailTool.h"

@implementation CommentDetailTool

///评论详情的接口（不包括标签和进度条）
+(void)refreshCommentDetailDataWithRequestStatus:(NSInteger )requestStatus withGoods_id:(NSInteger)goods_id withGrade:(NSInteger)grade withCurrent_page:(NSInteger)current_page withType:(NSInteger )type success:(void (^)(CommentDetailModel * commentDetailModel))successBlock
{
    if (requestStatus == 0) {
        [CommentDetailTool requstCommentRecordDataWithType:type withGrade:grade withGoods_id:goods_id success:successBlock];
    }else{
        [CommentDetailTool requstCommentRecordMoreDataWithGoods_id:goods_id withType:type withGrade:grade withCurrent_page:current_page success:successBlock];
    }
}

+(void)requstCommentRecordDataWithType:(NSInteger )type withGrade:(NSInteger)grade withGoods_id:(NSInteger)goods_id success:(void (^)(CommentDetailModel * commentDetailModel))successBlock
{
    NSString *url = [NSString stringWithFormat:@"%@app/comment_record",REQUESTHEADER];
    NSDictionary *dict = @{@"token":[FPLoginAndRegisterTools getToken],@"goods_id":@(goods_id),@"type":@(type),@"grade":@(grade),@"page":@(1)};//grade等级 好评 3 中评 2 差评 1
    [HttpManager postHttpRequestByPost:url andParameter:dict success:^(id successResponse) {
        NSDictionary *dic = successResponse;
        NSString *status = [NSString stringWithFormat:@"%@",dic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            CommentDetailModel * commentDetailModel = [[CommentDetailModel alloc] initWithDictionary:dic[@"data"] error:&error];
            if (successBlock) {
                successBlock(commentDetailModel);
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
    
    
}

+(void)requstCommentRecordMoreDataWithGoods_id:(NSInteger)goods_id withType:(NSInteger )type withGrade:(NSInteger)grade withCurrent_page:(NSInteger)current_page success:(void (^)(CommentDetailModel * commentDetailModel))successBlock
{
    NSString *url = [NSString stringWithFormat:@"%@app/comment_record",REQUESTHEADER];
    NSDictionary *dict = @{@"token":[FPLoginAndRegisterTools getToken],@"goods_id":@(goods_id),@"current_page":@(current_page),@"type":@(type),@"grade":@(grade)};
    [HttpManager postHttpRequestByPost:url andParameter:dict success:^(id successResponse) {
        NSDictionary *dic = successResponse;
        NSString *status = [NSString stringWithFormat:@"%@",dic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            //            current_page = [dic[@"data"][@"data"][@"last_page"] integerValue];
            NSError *error;
            CommentDetailModel * commentDetailModel = [[CommentDetailModel alloc] initWithDictionary:dic[@"data"] error:&error];
            if (successBlock) {
                successBlock(commentDetailModel);
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",dic[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
    
    
}

@end
